<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/layouts/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>编辑模板</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-dict-add">
		<input type="hidden"  name="id"  id="id"  value="${myTemplate.id }">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>模板名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${myTemplate.name }" placeholder="请输入模板名称" id="name" name="name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>模板类型：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box">
				<select class="select" size="1" name="type"  id="type">
					<c:forEach items="${fns:getDictList('temp_type')}"  var="tempType">
						<option value="${tempType.value }"  <c:if test="${myTemplate.type == tempType.value  }">selected</c:if> >${tempType.label }</option>
					</c:forEach>
				</select>
				</span>
			</div>
		</div>
		<div class="row cl" >
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>模板内容：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea style="height: 800px;" name="content"  id="content"  cols="500" class="textarea"  placeholder="请填写模板内容"  >${myTemplate.content }</textarea>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button  class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
	</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${ctxStatic}/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${ctxLib }/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="${ctxLib }/shopUtil.js"></script>
<script type="text/javascript">
$(function(){
	$("#form-dict-add").validate({
		rules:{
			name:{
				required:true
			},
			type:{
				required:true
			},
			content:{
				required:true
			}
		},
		messages: {
			  name: {
		        	required: "请输入模板名称"
		      },
		      type: {
		        	required: "请选择模板类型"
		      },
		      content:{
		    	  required:"请填写模板内容"
		      }
	    },
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
				var formData = ShopUtil.formToJSON();
				$.ajax({
                    type: 'POST',
                    url: '${ctx}/template/edit',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(formData),
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            layer.alert('编辑成功', {
                            	  closeBtn: 0
                            }, function(){
                            	window.parent.location.reload();
                            	var index = parent.layer.getFrameIndex(window.name);
                            	parent.layer.close(index);
                           	});
                        } else {
                            layer.alert(data.message);
                        }
                    }
                });
			}
		});
});	
</script>
</body>
</html>